package errorHandle;

import baseClass.ErrorParse;
import baseClass.ErrorToken;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
/*
    重新的语法错误处理类
    2022-3-9-杨海南
 */
public class ParserErrorHandle extends BaseErrorListener {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer,
                            Object offendingSymbol,
                            int line,//错误所在行号
                            int charPositionInLine,//错误在此行的第几个字符处
                            String msg,
                            RecognitionException e) {

        Token token = (Token) offendingSymbol;
        int start = token.getStartIndex();
        int end = token.getStopIndex();
        int type = token.getType();
        ErrorParse errorParse = new ErrorParse(line,charPositionInLine,msg,type,start,end);

        ErrorDeliver errorDeliver = ErrorDeliver.getErrorDeliverInstance();
        errorDeliver.addNewParseToken(errorParse);
    }
}
